package com.yitao.cms.controller.exchangeRate;

import com.skipper.base.bean.DataOutput;
import com.skipper.base.bean.PagedOutput;
import com.yitao.client.dto.exchangerate.ExchangeRateDto;
import com.yitao.cms.service.exchangeRate.ExchangeRateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Date: 2019/9/18 14:37
 * @Author: Kien
 */
@RestController
@RequestMapping(value = "/cms/exchangeRate", produces = {"application/json"})
@Api(description = "货币汇率", tags = {"cms-exchangeRate"})
public class ExchangeRateController {
    @Autowired
    private ExchangeRateService exchangeRateService;

    @ApiOperation("更新汇率")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public DataOutput saveExchangeRate(
            @ApiParam(value = "兑换币种(源币种)") @RequestParam(value = "sourceCurrency", required = false) String sourceCurrency,
            @ApiParam(value = "目标币种") @RequestParam(value = "targetCurrency", required = false) String targetCurrency,
            @ApiParam(value = "汇率") @RequestParam(value = "exchangeRate", required = false) String exchangeRate,
            @ApiParam(value = "银行发布时间") @RequestParam(value = "bankReleaseTime", required = false) String bankReleaseTime,
            @ApiParam(value = "发布银行") @RequestParam(value = "issueBank", required = false) String issueBank) {
        return exchangeRateService.saveExchangeRate(sourceCurrency, targetCurrency, exchangeRate, bankReleaseTime, issueBank);
    }

    @ApiOperation("查看汇率")
    @RequestMapping(value = "/findExchangeRate", method = RequestMethod.POST)
    public PagedOutput<ExchangeRateDto> findExchangeRate(@ApiParam(value = "兑换币种(源币种, 暂固定:AUD)") @RequestParam(value = "sourceCurrency", required = false) String sourceCurrency,
                                                        @ApiParam(value = "目标币种(暂固定:CNY)") @RequestParam(value = "targetCurrency", required = false) String targetCurrency,
                                                         @ApiParam(value = "分页参数，表示当前页", required = true, defaultValue = "1") @RequestParam(value = "pageNo") Integer pageNo,
                                                         @ApiParam(value = "分页参数，表示每页显示多少条记录", required = true, defaultValue = "10") @RequestParam(value = "pageSize") Integer pageSize){
        return exchangeRateService.findExchangeRate(sourceCurrency, targetCurrency, pageNo, pageSize);
    }

}
